package com.ljd.controller.front;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ljd.entity.EduCourse;
import com.ljd.entity.EduTeacher;
import com.ljd.service.EduCourseService;
import com.ljd.service.EduTeacherService;
import com.ljd.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/eduservice/indexfront")
//@CrossOrigin
public class IndexFrontController {
    @Autowired
    EduCourseService courseService;
    @Autowired
    EduTeacherService teacherService;

    //查询前8条热门课程，查询前4条名师
    @GetMapping("index")
    public R index(){
        // 前八条热门课程
        QueryWrapper<EduCourse> wrapper = new QueryWrapper<>();
        wrapper.orderByAsc("id")
                .last("limit 8");
        List<EduCourse> eduCourses = courseService.list(wrapper);

        // 前四条讲师
        QueryWrapper<EduTeacher> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByAsc("id")
                .last("limit 4");
        List<EduTeacher> teachers = teacherService.list(queryWrapper);

        return R.ok().data("courses",eduCourses).data("teachers",teachers);

    }
}
